<!--{template common/header_simple_start}-->
<link href="static/css/common.css?{VERHASH}" rel="stylesheet" media="all">
<script src="user/scripts/register.js?{VERHASH}"></script>
<script type="text/javascript" src="static/js/jquery.leftDrager.js?{VERHASH}"></script>
<!--{template common/header_simple_end}-->
<div class="bs-container clearfix">
	<div class="bs-left-container  clearfix">
		<!--{template left}-->
	</div>
	<div class="left-drager">
		<div class="left-drager-op">
			<div class="left-drager-sub"></div>
		</div>
	</div>
	<div class="bs-main-container  clearfix">
		<div class="main-content" style="padding:20px;">
			<form id="accountform" name="accountform" class="form-horizontal form-horizontal-left" role="form" action="user.php?mod=password" method="post" onsubmit="account_submit();return false">
				<input type="hidden" name="accountedit" value="true" />
				<input type="hidden" name="uid" value="$uid" />
				<input type="hidden" name="formhash" value="{FORMHASH}" />
				<div class="form-group">
					<label class="control-label" for="email">{lang login_email}</label>
					<input type="text" id="email" class="form-control" name="email" value="$user[email]">
					<span id="chk_email" class="help-inline"> <span id="suc_email"></span><kbd class="p_chk"></kbd> </span>

					<!--{if $user[groupid]==8}-->

					<ul class="help-block" style="color:#999">
						<li class="text-warning">{lang login_email}($user[email]){lang verify_account_limited}</li>
						<li>{lang user_send_activation_email}</li>
						<li>{lang receive_verification_email}
							<a href="javascript:;" onclick="$('email').focus()">{lang change_login_email}</a>{lang maybe}
							<a id="sendmail" href="user.php?mod=password&sendmail=1">{lang receive_validation_email}</a>
						</li>
					</ul>

					<!--{/if}-->
				</div>
				<div class="form-group">
					<label class="control-label" for="nickname">{lang username}</label>
					<input type="text" name="nickname" class="form-control" value="$user[nickname]" autocomplete="off" id="nickname" placeholder="{lang blank_not_set}">
					<span id="chk_nickname" class="help-inline"> <span id="suc_nickname"></span> <kbd class="p_chk"></kbd> </span>
				</div>
				<div class="form-group">
					<label class="control-label" for="phone">{lang phone_number}</label>
					<input type="text" name="phone" class="form-control" value="$user[phone]" autocomplete="off" id="phone" placeholder="{lang weixin_binding_mobile_phone}">
					<span id="chk_phone" class="help-inline">{lang phone_number_state}</span>
				</div>
				<div class="form-group">
					<label class="control-label" for="weixinid">{lang weixin}</label>
					<input type="text" name="weixinid" class="form-control" value="$user[weixinid]" autocomplete="off" id="weixinid" placeholder="{lang weixin}">
					<span id="chk_weixinid" class="help-inline">{lang weixin_state}</span>
				</div>
				<div class="form-group">
					<label class="control-label" for="password0" required>{lang original_password}</label>
					<input type="password" name="password0" class="form-control" autocomplete="off" id="password0" placeholder="{lang input_original_password}">
					<span id="chk_password0" class="help-inline"> <span id="suc_password0"></span> <kbd class="p_chk"></kbd> </span>
				</div>
				<div class="form-group">
					<label class="control-label" for="password">{lang new_password}</label>
					<input type="password" name="password" class="form-control" autocomplete="off" id="password" placeholder="{lang not_edit_please_blank}">
					<span id="chk_password" class="help-inline"> <span id="suc_password"></span> <kbd class="p_chk"></kbd> </span>
				</div>
				<div class="form-group">
					<label class="control-label" for="password2">{lang new_password_confirm}</label>
					<input type="password" id="password2" class="form-control" name="password2" autocomplete="off" placeholder="{lang not_edit_please_blank}">
					<span id="chk_password2" class="help-inline"> <span id="suc_password2"></span> <kbd class="p_chk"></kbd> </span>
				</div>
				<!--{if $secqaacheck || $seccodecheck}-->
				<!--{block sectpl}-->
				<sec>
				<sec>
				<sec>
				<!--{/block}-->
				<div class="form-group">
					<label class="control-label">{lang verification_code}</label>
					<div class="controls">
						<!--{template common/seccheck}-->
					</div>
				</div>
				<!--{/if}-->

				<div class="form-group">
					<label class="control-label"></label>
					<div class="controls"><input type="button" class="btn btn-primary" value="{lang save_changes}" onclick="account_submit()"></div>
				</div>
			</form>
		</div>
	</div>
</div>
<script type="text/javascript" reload="1">
	jQuery('.left-drager').leftDrager_layout();
	var orgsel_html = jQuery('#nav').html();
	var lastusername = '{$user[nickname]}',
		lastpassword = '',
		lastemail = '{$user[email]}',
		stmp = new Array(),
		modifypwd = true;
	var pwlength = 0;
	var strongpw = new Array();
	var ignoreEmail = false;

	checkPwdComplexity($('password'), $('password2'), 1);
	jQuery('#password0').on('blur', function() {
		if(jQuery(this).val() == '') {
			jQuery('#chk_password0 kbd').html('{lang please_input_original_password}');
			jQuery(this).parent().addClass('has-error');
		} else {
			jQuery('#chk_password0 kbd').html('');
			jQuery(this).parent().removeClass('has-error');
		}
	});
	jQuery('#email').on('blur', function() {
		var email = jQuery(this).val();
		var warnel = jQuery(this).parent();
		if(email == lastemail) {
			jQuery('#chk_email kbd').html('');
			jQuery(this).parent().removeClass('has-error');
		} else {
			var x = new Ajax();
			x.get('user.php?mod=ajax&inajax=yes&infloat=register&handlekey=password&ajaxmenu=1&action=checkemail&email=' + email, function(s) {
				if(s == 'succeed') {
					jQuery('#chk_email kbd').html('');
					warnel.removeClass('has-error');
				} else {
					jQuery('#chk_email kbd').html(s);
					warnel.addClass('has-error');
				}
			});

		}
	});
	jQuery('#nickname').on('blur', function() {
		var nickname = jQuery(this).val();
		var warnel = jQuery(this).parent();
		if(nickname == '' || nickname == lastusername) {
			jQuery('#chk_nickname kbd').html('');
			jQuery(this).parent().removeClass('has-error');
		} else {
			var x = new Ajax();
			x.get('user.php?mod=ajax&inajax=yes&infloat=register&handlekey=password&ajaxmenu=1&action=checkusername&username=' + nickname, function(s) {
				if(s == 'succeed') {
					jQuery('#chk_nickname kbd').html('');
					warnel.removeClass('has-error');
				} else {
					jQuery('#chk_nickname kbd').html(s.replace(/<a.+?\/a>/i, ''));
					warnel.addClass('has-error');
				}
			});

		}
	});

	function checkPwdComplexity(firstObj, secondObj, modify) {
		modifypwd = modify || false;
		firstObj.onblur = function() {
			if(firstObj.value != '') {
				var pwmsg = 'succeed';
				if(pwlength > 0) {
					pwmsg += ', {lang register_password_length_tips1} ' + pwlength + ' {lang register_password_length_tips2}';
				}
				errormessage(firstObj.id, pwmsg);
			} else {
				errormessage(firstObj.id, 'succeed');
			}
			checkpassword(firstObj.id, secondObj.id);
		};
		firstObj.onkeyup = function() {
			if(pwlength == 0 || $(firstObj.id).value.length >= pwlength) {
				var passlevels = new Array('', '{lang weak}', '{lang center}', '{lang strong}');
				var passlevel = checkstrongpw(firstObj.id);

				errormessage(firstObj.id, '<span class="passlevel passlevel' + passlevel + '">{lang cryptographic_strength}:' + passlevels[passlevel] + '</span>', 'passlevel');
			}
		};
		secondObj.onblur = function() {
			if(firstObj.value != '') {
				if(secondObj.value == '') {
					if(!modify) errormessage(secondObj.id, '{lang register_repassword_tips}');
				}
			}
			checkpassword(firstObj.id, secondObj.id);
		};
	}

	function checkpassword(id1, id2) {
		if(!$(id1).value && !$(id2).value) {
			errormessage(id2, 'succeed');
			errormessage(id1, 'succeed');
			return;
		}
		if(pwlength > 0) {
			if($(id1).value.length < pwlength) {
				errormessage(id1, '{lang password_short} ' + pwlength + ' {lang register_password_length_tips2}');
				return;
			}
		}
		if(strongpw) {
			var strongpw_error = false,
				j = 0;
			var strongpw_str = new Array();
			for(var i in strongpw) {
				if(strongpw[i] === 1 && !$(id1).value.match(/\d+/g)) {
					strongpw_error = true;
					strongpw_str[j] = '{lang strongpw_1}';
					j++;
				}
				if(strongpw[i] === 2 && !$(id1).value.match(/[a-z]+/g)) {
					strongpw_error = true;
					strongpw_str[j] = '{lang strongpw_2}';
					j++;
				}
				if(strongpw[i] === 3 && !$(id1).value.match(/[A-Z]+/g)) {
					strongpw_error = true;
					strongpw_str[j] = '{lang strongpw_3}';
					j++;
				}
				if(strongpw[i] === 4 && !$(id1).value.match(/[^A-Za-z0-9]+/g)) {
					strongpw_error = true;
					strongpw_str[j] = '{lang strongpw_4}';
					j++;
				}
			}
			if(strongpw_error) {
				errormessage(id1, '{lang password_weak} ' + strongpw_str.join('，'));
				return;
			}
		}
		errormessage(id2);
		if($(id1).value != $(id2).value) {
			errormessage(id2, '{lang profile_passwd_notmatch}');
		} else {
			errormessage(id2, 'succeed');
		}
	}
	function errormessage(id, msg,passlevel) {
		if($(id)) {
			msg = !msg ? '' : msg;
			if(msg == 'succeed') {
				msg = '';
				jQuery('#suc_' + id).addClass('p_right');
			} else if(msg !== '') {
				jQuery('#suc_' + id).removeClass('p_right');
			}
			jQuery('#chk_' + id).find('kbd').html(msg);
			if(msg && !passlevel) jQuery('#'+id).parent().addClass('has-warning');
			else jQuery('#'+id).parent().removeClass('has-warning');
		}
	}
	function account_submit() {

		//判断用户名

		if($('email').value == '') {
			jQuery('#email').parent().addClass('has-error');
			return false;
		} else if($('password0').value == '') {
			jQuery('#password0').parent().addClass('has-error');
			return false;
		} else if(($('password').value != '' || $('password2').value != '') && $('password').value != $('password2').value) {
			jQuery('#password0').parent().addClass('has-error');
			return false;
		}
		var p_chks = $('accountform').getElementsByTagName('kbd');
		var flag = 0;
		for(i = 0; i < p_chks.length; i++) {
			if(p_chks[i].className == 'p_chk' && p_chks[i].innerHTML != '') {
				return false;
			}
		}
		//判定微信号和手机
		var phone = $('phone').value;
		if(phone != '' && phone.match(/^\d+$/) == null) {
			$('phone').focus();
			showmessage('{lang phone_illegal}', 'danger', 1000, 1);
			return false;
		}
		var weixinid = $('weixinid').value;
		if(weixinid != '' && weixinid.match(/^[a-zA-Z\d_]{5,}$/) == null) {
			$('weixinid').focus();
			showmessage('{lang WeChat_id_illegal}', 'danger', 1000, 1);
			return false;
		}
		$('accountform').submit();
		return false;
	}
</script>
<!--{template common/footer_simple}-->